package com.hengyue.asset.domain.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.hengyue.common.core.entity.BaseEntity;
import com.hengyue.system.domain.entity.SysDept;
import com.hengyue.system.domain.entity.SysUser;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;

@EqualsAndHashCode(callSuper = true)
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Asset extends BaseEntity {

    @JsonSerialize(using = ToStringSerializer.class)
    @GeneratedValue(generator = "SnowIdGenerator")
    @GenericGenerator(type = com.hengyue.common.utils.SnowIdGenerator.class, name = "SnowIdGenerator")
    @Id
    private Long id;

    // 资产基本信息
    @Column(nullable = false, length = 100)
    private String assetName;          // 资产名称

    @Column(length = 50)
    private String assetCode;          // 资产编码

    @Column(length = 50)
    private String assetType;          // 资产类型

    @Column(length = 50)
    private String model;              // 规格型号

    @Column(length = 50)
    private String manufacturer;       // 生产厂家

    @Column(length = 50)
    private String supplier;           // 供应商

    // 财务信息
    @Column(precision = 12, scale = 2)
    private BigDecimal originalValue;   // 原值

    @Column(precision = 12, scale = 2)
    private BigDecimal netValue;       // 净值

    @Column(precision = 12, scale = 2)
    private BigDecimal depreciation;   // 累计折旧

    @Column(precision = 5, scale = 2)
    private BigDecimal depreciationRate; // 折旧率


    @ManyToOne
    @JoinColumn(name = "dept_id")
    private SysDept dept;      // 使用部门

    // 使用人
    @ManyToOne
    @JoinColumn(name = "user_id")
    private SysUser user;

    // 签字状态
    private Integer signatureStatus;



    // 管理员
    @ManyToOne
    @JoinColumn(name = "keeper_id")
    private SysUser keeper;


    @Column(length = 100)
    private String location;           // 存放地点

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private LocalDate purchaseDate;         // 购置日期

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    private LocalDate useDate;              // 启用日期

    @Column
    private Integer usefulLife;        // 使用年限(月)

    @JsonSerialize(using = ToStringSerializer.class)
    @Column(length = 20)
    private Integer status;             // 资产状态(在用/闲置/报废等)

    // 其他信息
    @Column(columnDefinition = "TEXT")
    private String remark;             // 备注

    @Column(length = 100)
    private String attachments;         // 附件路径

}

